package com.lcy.accumulation.export.setting;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>创建时间：2017-5-23 10:24</p>
 *
 * @author 娄存银
 * @version 1.0
 */
public class ExportHeader extends ExportItem {
    private List<ExportCell> cells;

    private ExportHeader(Integer row, Integer column, List<ExportCell> cells){
        this.row = row;
        this.column = column;
        this.cells = cells;
    }

    public void init(){
        if(cells != null){
            Integer column = getColumn();
            Integer row = getRow();
            if(row == null){
                row = 0;
            }
            if(column == null){
                column = 0;
            }
            for (ExportCell cell: cells) {
                if(cell != null){
                    if(cell.getRow() == null){
                        cell.setRow(row);
                    }else {
                        row = cell.getRow();
                    }

                    if(cell.getColumn() == null){
                        cell.setColumn(column);
                    }else {
                        column = cell.getColumn();
                    }
                }
                column++;
            }
        }
    }

    public void add(ExportCell cell){
        if(cell == null){
            return;
        }
        if(cells == null){
            cells = new ArrayList<>();
        }
        cells.add(cell);
    }

    public List<ExportCell> getCells() {
        return cells;
    }

    public void setCells(List<ExportCell> cells) {
        this.cells = cells;
    }
    public static ExportHeader getInstance(Integer row, Integer column, List<ExportCell> cells){
        if(cells == null || cells.size() == 0){
            return null;
        }
        if (row == null){
            row = 0;
        }
        if(column == null){
            column = 0;
        }
        ExportHeader header = new ExportHeader(row,column,cells);
        header.init();
        return header;
    }
}
